import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
import vuejsx from "@vitejs/plugin-vue-jsx"
//打包分析插件
import { visualizer } from 'rollup-plugin-visualizer'
let _resolve = (dir) => {
  return path.resolve(dir)
}

import autoPluginImport from "unplugin-auto-import/vite"
// https://vitejs.dev/config/
export default ({ mode }) => defineConfig({
  plugins: [
    vue(),
    vuejsx({}),
    visualizer(),
    autoPluginImport({
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/, /\.vue\?vue/, // .vue
        /\.md$/, // .md
      ],
      defaultExportByFilename: true,
      imports: ["vue", "vue-router", "pinia", "vuex", "@vueuse/head","@vueuse/core" ,{
        //配置自动导入api模块,不在需要再组件中引入
        // 文件路径         //导出模块名字  //给模块取别名
        "@/api/index.js": ["allModules", ["allModules", "api"]]
      }],
      //这个是配置默认导出模块的
      // dirs:["./src/api/"]
    })
  ],
  //打包资源配置
  base: './',
  resolve: {
    //配置别名
    alias: {
      "@": _resolve('src')
    }
  },
  server: {
    port: 8080,
    proxy: {
      "/api": {
        target: "http://chst.vip",
        rewrite: path => path.replace(/^\/api/, "")
      },
      // http://heymock.uneedcode.com
      "/other": {
        target: "http://heymock.uneedcode.com",
        changeOrigin:true,
        rewrite: path => path.replace(/^\/other/, "")
      }
    }
  }
})
